package com.woniuxy.kaer.tenants.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.kaer.commons.jwtUtil.JwtUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.tenants.dto.ShopDto;
import com.woniuxy.kaer.tenants.dto.ShopInfoDto;
import com.woniuxy.kaer.tenants.dto.ShopServiceDto;
import com.woniuxy.kaer.tenants.entity.ShopInfo;
import com.woniuxy.kaer.tenants.from.*;
import com.woniuxy.kaer.tenants.param.*;
import com.woniuxy.kaer.tenants.service.ShopInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 程诗洋
 * @since 2025年2月17日
 */
@RestController
@RequestMapping("/shopInfo")
@Api(tags = "商家店铺信息类")
public class ShopInfoController {
    @Resource
    private ShopInfoService shopInfoService;
    @Resource
    private JwtUtil jwtUtil;
    @ApiOperation("完善商家信息接口")
    @PostMapping("/refineTenantsInfo")
    public Result refineTenantsInfo( RefineTenantsInfoFrom from,@RequestHeader("token") String token)throws Exception{
        Integer founderId = jwtUtil.getFounderId(token);
        RefineTenantsInfoParam refineTenantsInfoParam = BeanUtil.toBean(from, RefineTenantsInfoParam.class);
        refineTenantsInfoParam.setFounderId(founderId);
        shopInfoService.refineTenantsInfo(refineTenantsInfoParam);
        return Result.succeed("完善商家信息成功",null);
    }
    @ApiOperation("通过id的查询商铺信息接口")
    @GetMapping("/getShopInfoByShopId")
    public Result<ShopInfoDto> getShopInfoByShopId(Integer shopId)throws Exception{
        ShopInfoDto shopInfoDto = shopInfoService.getShopInfoByShopId(shopId);
        return Result.succeed("通过id查询商铺成功",shopInfoDto);
    }
    //更新店铺评分
    @ApiOperation("更新店铺评分接口")
    @PutMapping("/updateShopScore")
    public Result updateShopScore(@RequestBody UpdateShopScoreFrom from)throws Exception{
        UpdateShopScoreParam updateShopScoreParam = BeanUtil.toBean(from, UpdateShopScoreParam.class);
        shopInfoService.updateShopScore(updateShopScoreParam);
        return Result.succeed("更新店铺评分成功",null);
    }
    @ApiOperation("通过关键字查询商铺信息接口")
    @GetMapping("/selectShopByServiceName")
    public Result selectShopByServiceName(SelectShopByServiceNameFrom from)throws Exception {
        SelectShopByServiceNameParam selectShopByServiceNameParam = BeanUtil.toBean(from, SelectShopByServiceNameParam.class);
        List<ShopDto> shopDtoList = shopInfoService.selectShopByServiceName(selectShopByServiceNameParam);
        return Result.succeed("通过关键字查询商铺成功", shopDtoList);
    }
    //查询商户信息
    @ApiOperation("查询商户信息接口")
    @GetMapping("/getShopInfoByToken")
    public Result getShopInfoByFounderId(@RequestHeader("token") String token)throws Exception{
        Integer founderId = jwtUtil.getFounderId(token);
        ShopInfoDto shopInfoDto = shopInfoService.getShopInfoByFounderId(founderId);
        return Result.succeed("查询商户信息成功",shopInfoDto);
    }
    //通过founderId查询商户信息
    @ApiOperation("通过 founderId查询商户信息接口")
    @GetMapping("/getShopInfoByFounderId")
    public Result<ShopInfoDto> getShopInfoByFounderId(Integer founderId)throws Exception{
        ShopInfoDto shopInfoDto = shopInfoService.getShopInfoByFounderId(founderId);
        return Result.succeed("通过 founderId查询商户信息成功",shopInfoDto);
    }
    //查询所有商铺信息
    @ApiOperation("查询所有商铺信息接口")
    @GetMapping("/getAllShopInfo")
    public Result<List<ShopInfoDto>> getAllShopInfo()throws Exception{
        List<ShopInfoDto> shopInfoDtoList = shopInfoService.getAllShopInfo();
        return Result.succeed("查询所有商铺信息成功",shopInfoDtoList);
    }
    //每天网上12点更新店铺评分，和店铺服务数量
    @ApiOperation("每天网上12点更新店铺评分，和店铺服务数量接口")
    @PostMapping("/shopServiceCount")
    public Result shopServiceCount(@RequestBody ChangeShopScoreFrom from)throws Exception{
        System.out.println("店铺Id"+from.getShopId());
        ChangeShopScoreParam changeShopScoreParam = BeanUtil.toBean(from, ChangeShopScoreParam.class);
        shopInfoService.shopServiceCount(changeShopScoreParam);
        return Result.succeed("每天网上12点更新店铺评分，和店铺服务数量成功",null);
    }
    //通过商铺名查询商铺服务
    @ApiOperation("通过商铺名查询商铺服务接口")
    @GetMapping("/getShopInfoByShopName")
    public Result getShopInfoByShopName(GetShopServiceFrom from)throws Exception{
        GetShopServiceParam getShopServiceParam = BeanUtil.toBean(from, GetShopServiceParam.class);
        List<ShopServiceDto> shopServiceDtoList = shopInfoService.getShopInfoByShopName(getShopServiceParam);
        return Result.succeed("通过商铺名查询商铺服务成功",shopServiceDtoList);
    }

}

